//菜品设置数据存放
import http from '../../../http/http'
import * as url from '../../../api/lypApi'
const state = {
  staffTableData:[],
  token:sessionStorage.getItem('token') || undefined
};
const actions = {
  getStaffData({commit}){
    return http({
      url:`/lypApi${url.GETSTAFF}`,
      method:"post",
    }).then(res=>{
      console.log(res)
      this.staffTableData=res.data.list
      console.log(this.staffTableData)
      commit('addStaffData',res.data.list)
    })
  },
  deleteStaffData({commit},obj){
    console.log(obj.id)
    // let delData=[]
    let delData=this.staffTableData.filter(item=> item.id!=obj.id)
    this.staffTableData=delData
    // let data=this.staffTableData.filter(item=> item.id==obj.id)
    http({
      url:`/lypApi${url.DELSTAFF}`,
      method:'post',
      data:{
        "id":obj.id
      },
    }).then(res=>{
      console.log(res)
      if (res.status===200){

        // delData=res.data.list
        // this.staffTableData=delData
      }
    }).catch(err=>{
      console.log(err)
    })
    commit('addStaffData',delData)
  },
  selectStaffData({dispatch,commit},obj){
    console.log(obj)
    // return dispatch('getData').then(() => {
    //   // commit('someOtherMutation')
    // })
    let selectData=[]
    this.staffTableData.forEach((item)=>{
      if (item[obj[0]]==obj[1]){
        console.log(item)
        selectData.push(item)
      }
    })
    return selectData
  }
};
const mutations = {
  addStaffData(state,obj){
    state.staffTableData = obj
    console.log(this.staffTableData)
  }
}
const  getters= {

};
export default {
  state,
  actions,
  mutations,
  getters
}
